﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Licenta1;
using Licenta1.Expressions;
using System.Collections;

namespace Licenta1.Statements
{
    class AssignmentStatement : Statement
    {
        String identifier;
        Expression toAssignExpr;

        public AssignmentStatement(Context con, Expression id, Expression expr)
            : base(con)
        {
            try
            {
                identifier = ((IdentifierExpression)id).Name;
                toAssignExpr = expr;
            }
            catch (Exception)
            {
                identifier = "";
            }
        }

        public override void Execute()
        {
            if (context.variables != null && identifier != "")
            {
                if (context.variables.ContainsKey(identifier))
                    context.variables[identifier] = toAssignExpr.Value;
                else context.variables.Add(identifier, toAssignExpr.Value);
            }
        }

        public String IDENTIFIER
        {
            get { return identifier; }
        }

        public Expression EXPRESSION
        {
            get { return toAssignExpr; }
        }
    }
}